package com.Suyin.pma.Dao;

import com.Suyin.pma.Entities.Student;
import com.Suyin.pma.dto.StudentProject;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

@Repository
public interface StudentRepository extends CrudRepository<Student,Long>  {

    @Override
    List<Student> findAll();

    @Query(nativeQuery = true,value = "SELECT s.name, s.wechat AS wechat, COUNT(s.ID) AS projectCount " +
            "FROM student AS s LEFT JOIN project_student AS ps ON s.ID = ps.student_id " +
            "GROUP BY s.name, s.ID ORDER BY 3 desc; ")
    List<StudentProject> studentProjects();

    Student findByStudentId(long theId);
}
